# Contributor: fossdd <fossdd@pwned.life>
# Maintainer: fossdd <fossdd@pwned.life>
pkgname=ntpd-rs
pkgver=1.3.0
pkgrel=0
pkgdesc="Full-featured implementation of the Network Time Protocol, including NTS support"
url="https://docs.ntpd-rs.pendulum-project.org/"
arch="all"
license="Apache-2.0 OR MIT"
makedepends="cargo-auditable"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/pendulum-project/ntpd-rs/archive/refs/tags/v$pkgver.tar.gz
	ntpd-rs.initd
	ntpd-rs-metrics-exporter.initd
	"
options="!check net" # fails, downloading rust crates

prepare() {
	default_prepare
	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --frozen --release
}

check() {
	cargo test --frozen --release
}

package() {
	for i in ntp-daemon ntp-ctl ntp-metrics-exporter; do
		install -Dm755 target/release/$i \
			-t "$pkgdir"/usr/bin/
	done

	# default config
	install -Dm644 docs/examples/conf/ntp.toml.default \
		"$pkgdir"/etc/ntpd-rs/ntp.toml

	# openrc
	install -Dm755 "$srcdir"/ntpd-rs.initd \
		"$pkgdir"/etc/init.d/ntpd-rs
	install -Dm755 "$srcdir"/ntpd-rs-metrics-exporter.initd \
		"$pkgdir"/etc/init.d/ntpd-rs-metrics-exporter

	# man pages
	for i in ntp-daemon.8 ntp-ctl.8 ntp-metrics-exporter.8; do
		install -Dm644 docs/precompiled/man/$i \
			-t "$pkgdir"/usr/share/man/man8
	done

	install -Dm644 docs/precompiled/man/ntp.toml.5 \
		-t "$pkgdir"/usr/share/man/man5

	install -Dm644 README.md -t "$pkgdir"/usr/share/doc/$pkgname/
	install -Dm644 CHANGELOG.md -t "$pkgdir"/usr/share/doc/$pkgname/
	install -Dm644 SECURITY.md -t "$pkgdir"/usr/share/doc/$pkgname/
	install -Dm644 LICENSE-MIT -t "$pkgdir"/usr/share/doc/$pkgname/
	install -Dm644 LICENSE-APACHE -t "$pkgdir"/usr/share/doc/$pkgname/
}

sha512sums="
97083409e569f922ad324f358df914c0668ba084c630ddcf17e06008dcdffe95f3e08a523689f0258b35091c0efb4055b03bd70f538335c52391422bc8e376bf  ntpd-rs-1.3.0.tar.gz
57220d9d446084178a36ee7e01fde157d38ed685d3bf3b71da66b88f343a16778d4919a7d4416efd445053d6bbbef6d8b9e6d64d5f9d4598e8b53ae98aa277b2  ntpd-rs.initd
0a75a0d2ac77e0754f180df880dc7b0ef2c525cde5c575ffccfafef4ba06a59cbcd7bd0a1a313649a0674def8353f3333be692054b7416f4b9302124f5be3aeb  ntpd-rs-metrics-exporter.initd
"
